<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>选项卡4</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        ul,
        li {
            list-style: none;
        }

        .container {
            width: 400px;
            margin: 100px auto;
        }

        ul {
            display: flex;
            width: 100%;
        }

        li {
            flex: 1;
            background-color: rosybrown;
            border: 1px solid darkblue;
            text-align: center;
            padding: 5px 0;
            cursor: pointer;
            font-size: 12px;
        }

        .box {
            width: 400px;
            height: 200px;
            background-color: darkkhaki;
            text-align: center;
            line-height: 200px;
        }

        /* 1. 设置选中样式 */
        .active {
            background-color: red;
        }
    
        ol,li{
            list-style: none;
        }

        ol{
            position: relative;
            width: 400px;
            height: 200px;
        }
        ol>li{
            position: absolute;
            width: 400px;
            height: 200px;
            line-height: 200px;
            background-color: pink;
            font-size: 28px;
            display: none;
        }
        .on{
            display: block;
        }

    </style>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
</head>

<body>
    <!-- 
        选项卡思路:
           1. 设置选中样式active
           2. 所有选项绑定事件
              2.1  清除所有选中样式
              2.2 当前选中选项设置样式


     -->
    <div class="container">
        <ul>
            <li class="active">选项1</li>
            <li>选项2</li>
            <li>选项3</li>
        </ul>
        <ol>
            <li style="background-color: chocolate;" class="on">容器1</li>
            <li style="background-color: blueviolet;">容器2</li>
            <li style="background-color: brown;">容器3</li>
        </ol>
    </div>

    <script src="js/jquery-3.6.0.js"></script>
    <script>
        $('ul>li').on('click',function(){
            //2.1  清除所有选中样式
            $(this).addClass('active').siblings().removeClass('active')

            let index = $(this).index() //序号
            $('ol>li').eq(index).slideDown(2000).siblings().slideUp(2000)
        })
    </script>

</body>

</html>